import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'
// import nameOpt from '@/biz/option/name.js'

function options(_this, isAudit = false) {
  return [

    {
      title: '角色名称',
      field: 'roleName',
      minWidth: 120,
      slots: {

        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '角色名称',
            key: 'roleName',
            placeholder: '请输入角色名称',
            input: {}
          })
        },
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.roleName,
          })
        },
      }
    },
    {
      title: '角色类型',
      field: 'roleType',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '角色类型',
            key: 'roleType',
            placeholder: '请选择',
            select: {
              options: [{
                value: '前台角色',
                key: 1
              },
              {
                value: '后台角色',
                key: 2
              }, ],
            }
          })
        },
        default: (params, h) => {
          return [h('div', params.row.roleType == 1 ? '前台角色' : '后台角色')]
        }
      }
    },
    {
      title: '端口权限',
      field: 'portList',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '端口权限',
            key: 'port',
            placeholder: '请选择端口权限',
            select: {
              options: [{
                value: 'web端',
                key: 'web'
              },
              {
                value: 'App端',
                key: 'app'
              }, ],
            }
          })
        },
        default: (params, h) => {
          return [h('div', params.row.portList.join(','))]
        }
      },
    },
    {
      title: '数据权限',
      field: 'permissionType',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '数据权限',
            key: 'permissionType',
            placeholder: '请选择数据权限',
            select: {
              options: dt.dictInfo().permissionType
            }
          })
        },
        default: (params, h) => {
          return [h('div', _this.permissionTypeTransformation(params.row.permissionType))]
        }
      },
    },
    {
      title: '角色状态',
      field: 'validate',
      minWidth: 120,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '角色状态',
            key: 'validate',
            placeholder: '请选择角色状态',
            select: {
              options: [{
                value: '有效',
                key: '1'
              },
              {
                value: '无效',
                key: '2'
              }, ],
            }
          })
        },
        default: (params, h) => {
          return [h('div', params.row.validate == 1 ? '有效' : '无效')]
        }
      },
    },
    {
      title: '创建时间',
      key: 'createTime',
      minWidth: 180,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '创建时间',
            placeholder: '请选择时间',
            date: {
              type: 'daterange'
            },
            data: {
              to: (val) => {
                return {
                  beginDate: val[0],
                  endDate: val[1]
                }
              }
            }
          })
        },
        default: (params, h) => {
          return [h('div', params.row.createTime.split(' ')[0])]
        }
      },

    },
    {
      title: '备注',
      key: 'roleDesc',
      minWidth: 240,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.roleDesc,
          })
        },
      }
    },
    {
      title: '操作',
      key: '',
      fixed: 'right',
      width: 180,
      align: 'center',
      slots: {
        default: (params, h) => {
          // let arr = ['店长', '运营策划', '管理员'],
          let arr = [], //指定不可更改编辑的角色
            flag = arr.findIndex((item) => item == params.row.roleName)
          let btns = []
          let item = params.row
          if (flag == -1) {
            btns.push({
              title: _this.unlocking('0202020000') ? '编辑' : '',
              event: 'editMess',
              data: item
            })

            btns.push({
              title: _this.unlocking('0202030000') ? params.row.validate ==
                2 ? '开启' : '禁用' : '',
              event: 'openAuthority',
              data: item
            })
          }
          return table.cell.btns(_this, h, btns)
        }
      },
    },
  ]
}

export default {
  options
}